<?php
/*
 * @Author: your name
 * @Date: 2019-12-02 11:16:35
 * @LastEditTime : 2020-01-06 11:18:16
 * @LastEditors  : Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /ahsmp_3/application/asmpasync/service/DisGuise.php
 */
namespace app\asmpasync\service;

use app\common\service\module_manage\disguise\HostGuiseConfig;
use think\Db;

class DisGuise
{
    public $classDescription = '系统伪装服务';//模块描述
    public $actionDescription = '';//操作描述
    /**
     * @name: 端口信息
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-12-02 11:18:06
     */
    private function Port ($guisePort)
    {
        $return = array_map(function ($v)
        {
            $Port = new \Disguise\Port();
            $Port->setProto($v['protocols'] == 1 ? 'tcp' : 'udp');
            $Port->setPort($v['port']);
            return $Port;
        }, $guisePort);

        return $return;
    }

    /**
     * @name: 伪装信息
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-12-02 11:23:37
     */
    public function Disguise ($host_id)
    {
        $this->actionDescription = '伪装信息';
        $HostGuiseConfig = new HostGuiseConfig();
        $config = $HostGuiseConfig->findOne($host_id);
        
        if ($config['guise_status'] == 1)
        {
            $guisePort = Db::name('HostGuisePort')->field('port,protocols')->where('host_id', $host_id)->select();
            $guisePort = $this->Port($guisePort);
        }
        else
        {
            $guisePort = [];
        }
        
        $Disguise = new \Disguise\Disguise();
        $Disguise->setPorts($guisePort);

        return $Disguise;
    }
}